package com.bestv.c2.task;

import com.bestv.c2.handler.SyncHandler;

import java.io.IOException;
import java.text.ParseException;

/**
 * Created by Henry on 15/9/2.
 */
public class SyncDataTask extends Task {
    private SyncHandler[] handlers;

    @Override
    public void execute() {
        logger.info("Starting csv data output task...");

        try {
            for (SyncHandler handler : handlers) {
                long time = System.currentTimeMillis();
                handler.handle();
                long length = System.currentTimeMillis() - time;
                logger.info("End sync data for: {}, times(ms): {}.", handler.getExportFilePath(), length);
            }
        } catch (IOException e) {
            logger.error("Error on IO.", e);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        logger.info("Finish csv data output task.");
    }

    public SyncHandler[] getHandlers() {
        return handlers;
    }

    public void setHandlers(SyncHandler[] handlers) {
        this.handlers = handlers;
    }
}
